package com.study.controller;

import com.study.bean.query.RecordQuery;
import com.study.service.RecordService;
import com.study.service.impl.RecordServiceImpl;
import com.study.util.MyBeanUtils;
import com.study.util.PageInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/record")
public class RecordController extends BaseController{

    private final RecordService studentService = new RecordServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");

        switch (method){
            case "selectByPage":
                selectByPage(req, resp);
                break;
                default:
                    break;
        }
    }

    private void selectByPage(HttpServletRequest req, HttpServletResponse resp) {
        System.out.println("RecordController.selectByPage");

        RecordQuery recordQuery = MyBeanUtils.copyToBean(req, RecordQuery.class);
        System.out.println(recordQuery);
        PageInfo pageInfo = studentService.selectByPage(recordQuery);

        //JSONUtils.toJSON(resp, pageInfo);
        toJSON(resp, pageInfo);
    }

}
